package com.baizhi.service.impl;

import com.baizhi.entity.Admin;
import com.baizhi.entity.Menu;
import com.baizhi.entity.Role;
import com.baizhi.mapper.MenuMapper;
import com.baizhi.service.IMenuService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜单管理 服务实现类
 * </p>
 *
 * @author longyang
 * @since 2022-01-13
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {
    @Autowired
    private MenuMapper menuMapper;
    @Override
    public List<Menu> selectMenu(Integer uid) {
        List<Menu> menus = menuMapper.selectMenu(uid);
        return menus;
    }

    @Override
    public List<Menu> selectMenuAll() {
        List<Menu> menus = menuMapper.selectList(null);
        return menus;
    }

    @Override
    public Integer updateMenu(Menu menu) {
        return menuMapper.updateById(menu);
    }

    @Override
    public List<Menu> selectChildrenByPid(Integer resourceId) {
        //条件构造器：用于构建sql条件
        QueryWrapper<Menu> queryWrapper = new QueryWrapper<Menu>();
        queryWrapper.eq("parent_id",resourceId);
        return menuMapper.selectList(queryWrapper);
    }
}
